package com.example.thread;

/**
 * @author hl
 */
public class ThreadInterface implements Runnable{
    volatile boolean flag = false;

    private EnergySystem energySystem;
    private int boxIndex;
    private double amout;
    public ThreadInterface(EnergySystem energySystem,int boxIndex,double amout){
        this.energySystem = energySystem;
        this.boxIndex = boxIndex;
        this.amout = amout;
    }
    @Override
    public void run() {
        try {
                while (true) {
                    int tobox = (int) (energySystem.getBoxSize() * Math.random());
                    double amount = amout * Math.random();
                    energySystem.transfer(boxIndex, tobox, amount);
                    Thread.sleep(5000);
                }
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }

//    private int num;
//    ThreadInterface(int i){
//        this.num = i;
//    }
//    @Override
//    public void run() {
//        synchronized (lock) {
//            while (num < 10) {
//                System.out.println(Thread.currentThread().getName() + "i:" + (++num));
//            }
//        }
//    }
}
